import axios from 'axios';

// 创建 axios 实例
const service = axios.create({
  baseURL: 'http://localhost:3000',
  timeout: 50000,
  headers: { 'Content-Type': 'application/json;charset=utf-8' },
});

// 请求拦截器
service.interceptors.request.use(
  (config) => {
    
    return config;
  },
  (error) => {
    return Promise.reject(error);
  }
);

// 响应拦截器
service.interceptors.response.use(
  (response) => {
    
    const { code } = response.data;

    if (code === 0) {
      return response.data;
    }
  },
  (error) => {
  
    return Promise.reject(error.response);
  }
);

// 导出 axios 实例
export default service;
